package com.pwx.student.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Copyright (C),2021-2022,亚瑟王
 * FileName: ResponseResult
 * Author: saber
 * Date:2022/10/25 20:55
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseResult<T> {
    private int code;//设置响应状态 1成功 0失败
    private String msg;//响应的信息
    private T data;//响应的数据

    /* 设置通用的返回方法 */
    /* 成功响应方法 */
    public static ResponseResult createSuccess() {
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getComment(), null);
    }

    public static <T> ResponseResult<T> createSuccess(T data) {
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getComment(), data);
    }

    public static ResponseResult createSuccess(String msg) {
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), msg, null);
    }

    public static <T> ResponseResult<T> createSuccess(String msg, T data) {
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), msg, data);
    }

    /* 失败响应方法 */
    public static ResponseResult createFail() {
        return new ResponseResult(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getComment(), null);
    }

    public static <T> ResponseResult<T> createFail(T data) {
        return new ResponseResult(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getComment(), data);
    }

    public static ResponseResult createFail(String msg) {
        return new ResponseResult(ResponseCode.FAIL.getCode(), msg, null);
    }

    public static <T> ResponseResult<T> createFail(String msg, T data) {
        return new ResponseResult(ResponseCode.FAIL.getCode(), msg, data);
    }

    /* 通用自定义参数方法 */
    public static <T> ResponseResult<T> createResponse(int code, String msg, T data) {
        return new ResponseResult(code, msg, data);
    }
} 
